<include file="/public/header" />
<style>
    .layui-table-cell {
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
        height: auto;
        /*在这里设置行高没用*/
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="type">
                                <option value="">{:__('订单类型')}</option>
                                <option value="2">{:__('已发货|已确认门店兑换')}</option>
                                <option value="1">{:__('物流发货')}</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value="">{:__('状态查询')}</option>
                                <option value="4">{:__('取消')}</option>
                                <option value="3">{:__('完成')}</option>
                                <option value="2">{:__('已发货|已确认')}</option>
                                <option value="1">{:__('待发货|待确认门店信息')}</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="{:__('关键字搜索')}" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit><i
                                class="layui-icon layui-icon-search"></i>{:__('搜索')}</button>
                        <div class="layui-divider layui-divider-vertical"></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    {{#  if(d.status ==1){ }}
        <a class="layui-table-text" style="color:#FF5722" data-url="/admin/system/porder/status?id={{d.id}}&status=4" data-reload="self" data-confirm="" lay-ajax="">取消</a>
        <div class="layui-divider layui-divider-vertical"></div>
        {{#  if(d.type ==1){ }}
        <a class="layui-table-text" data-title="{:__('填写快递信息')}" callback="edits"  data-url="#editforms" lay-event="edit">{:__('填写快递信息')}</a>
        {{#  } }}
        {{#  if(d.type ==2){ }}
        <a class="layui-table-text" data-title="{:__('填写门店信息')}" callback="edits"  data-url="#editforms2" lay-event="edit">{:__('填写门店信息')}</a>
        {{#  } }}
        <div class="layui-divider layui-divider-vertical"></div>
        <a class="layui-table-text" style="color:#FF5722" data-url="/admin/system/porder/status?id={{d.id}}&status=3" data-reload="self" data-confirm="" lay-ajax="">完成</a>
    {{# }if(d.status ==2) { }}
    <a class="layui-table-text" style="color:#FF5722" data-url="/admin/system/porder/status?id={{d.id}}&status=4" data-reload="self" data-confirm="" lay-ajax="">取消</a>
    <div class="layui-divider layui-divider-vertical"></div>
    {{#  if(d.type ==1){ }}
    <a class="layui-table-text" data-title="{:__('更改快递信息')}" callback="edits"  data-url="#editforms" lay-event="edit">{:__('更改快递信息')}</a>
    {{#  } }}
    {{#  if(d.type ==2){ }}
    <a class="layui-table-text" data-title="{:__('更改门店信息')}" callback="edits"  data-url="#editforms2" lay-event="edit">{:__('更改门店信息')}</a>
    {{#  } }}
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" style="color:#FF5722" data-url="/admin/system/porder/status?id={{d.id}}&status=3" data-reload="self" data-confirm="" lay-ajax="">完成</a>
    {{# }if(d.status ==3) { }}
    已完成
    {{# }if(d.status ==4) { }}
已取消
    {{#  } }}
</script>

<script type="text/html" id="editforms">
    <div class="layui-fluid layui-bg-white" >
        <form class="layui-form layui-form-fixed" lay-filter="editforms">
        <input type="text" name="id" hidden="">
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('快递名称')}</label>
            <div class="layui-input-block">
                <input name="delname" placeholder="{:__('快递名称')}" type="text" class="layui-input"  lay-verify="required" />
            </div>
        </div>  
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('快递单号')}</label>
            <div class="layui-input-block">
                <input name="delnumber" placeholder="{:__('快递单号')}" type="text" class="layui-input"  lay-verify="required" />
            </div>
        </div>                 
        <div class="layui-footer layui-form-item layui-center "  >
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >{:__('取消')}</button>
            <button class="layui-btn" lay-add="{:url('/system/porder/status')}" lay-edit="{:url('/system/porder/status')}" lay-filter="submitPage" lay-submit>{:__('提交')}</button>
        </div>
        </form>
    </div>
</script>

<script type="text/html" id="editforms2">
    <div class="layui-fluid layui-bg-white" >
        <form class="layui-form layui-form-fixed" lay-filter="editforms2">
        <input type="text" name="id" hidden="">
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('门店名称')}</label>
            <div class="layui-input-block">
                <input name="storename" placeholder="{:__('门店名称')}" type="text" class="layui-input"  lay-verify="required" />
            </div>
        </div>  
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('门店地址')}</label>
            <div class="layui-input-block">
                <input name="storeaddress" placeholder="{:__('门店地址')}" type="text" class="layui-input"  lay-verify="required" />
            </div>
        </div>                 
        <div class="layui-footer layui-form-item layui-center "  >
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >{:__('取消')}</button>
            <button class="layui-btn" lay-add="{:url('/system/porder/status')}" lay-edit="{:url('/system/porder/status')}" lay-filter="submitPage" lay-submit>{:__('提交')}</button>
        </div>
        </form>
    </div>
</script>
<!-- // 列表状态栏 -->
<script type="text/html" id="tableXx">
    {{#  if(d.type ==1){ }}
    <div>快递名称:{{d.delname}}</div>
    <div>快递单号:{{d.delnumber}}</div>
    {{# }if(d.type ==2) { }}
    <div>门店名称:{{d.storename}}</div>
    <div>门店地址:{{d.storeaddress}}</div>
    {{#  } }}
</script>
<!-- // 列表状态栏 -->
<script type="text/html" id="columnType">
    {{#  if(d.type ==1){ }}
    快递发货
    {{# }if(d.type ==2) { }}
    门店兑换
    {{#  } }}
</script>
<script type="text/html" id="columnStatus">
    {{#  if(d.status ==1){ }}
    待发货/待确认门店信息
    {{# }if(d.status ==2) { }}
    已发货/确认门店信息
    {{# }if(d.status ==3) { }}
    已完成
    {{# }if(d.status ==4) { }}
    已取消
    {{#  } }}
</script>
<include file="/public/footer" />
<script>
    layui.use(['admin', 'layedit', 'table', 'form', 'content'], function () {
        var admin = layui.admin;
        var table = layui.table;
        var form = layui.form;
        var layedit = layui.layedit;
        var content = layui.content;
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url('/system/porder/index')}"
            , page: true
            , limit: 18
            , cols: [[
                { type: 'checkbox', width: 50 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'type', align: 'center', templet: '#columnType', title: '{:__("订单类型")}' },
                { field: 'ordersn', align: 'left', title: '{:__("订单号")}' },
                {
                    field: 'mobile', align: 'left', title: '{:__("商品信息")}', templet: function (d) {
                        html = '<div>';
                        html += '<div>' + d.goodsinfo.title ? d.goodsinfo.title + '</div>' : '';
                        html += '<div>' + d.goodsinfo.numbers ? '数量:X' + d.goodsinfo.numbers + '</div>' : '';

                        html += '<div>' + d.goodsinfo.images ? '<img src="' + d.goodsinfo.images + '" width="50" height="50" lay-image-hover="" ></div>' : '';
                        html += '</div>'
                        return html;
                    }
                },
                { field: 'name', align: 'left', title: '{:__("用户")}' },
                { field: 'mobile', align: 'left', title: '{:__("手机号")}' },
                { align: 'center', toolbar: '#tableXx', width: 160, title: '信息' },
                {
                    field: 'mobile', align: 'left', title: '{:__("用户地址")}', templet: function (d) {
                        return d.province + d.city + d.area + d.address;
                    }
                },
                { field: 'type', align: 'center', templet: '#columnStatus', title: '{:__("上架状态")}' },
                { field: 'total', align: 'left', title: '{:__("消耗总积分")}' },

                { field: 'create_time', align: 'center', width: 180, title: '{:__("添加时间")}' },
                { align: 'center', toolbar: '#tableBar', width: 160, title: '{:__("操作")}' },
            ]],
            done: function () {
                //当数据渲染完后，执行的回调
            }
        })
        // 添加 / 编辑用户
        admin.callback.edits = function (clickthis, colletction, config) {

            // 获取表格对象
            var tableThis = colletction.tableThis,
                status = typeof (tableThis) === "undefined" ? true : false;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {
                // 获取用户id
                var pageThat = layui.$(this),
                    _pageUrl = !status ? pageThat.attr('lay-edit') : pageThat.attr('lay-add');
                // 开始POST提交数据
                post.field.status = 2;
                layui.$.post(_pageUrl,
                    post.field, function (res) {
                        if (res.code === 200) {
                            layer.msg(res.msg);
                            // 关闭当前窗口
                            table.reload('lay-tableList');
                            layer.close(colletction.index);
                            pageThat.attr("disabled", true);
                        }
                        else {
                            layer.error(res.msg);
                        }

                    }, 'json');

                return false;
            })
        }
    })
</script>